package vip.xiaonuo.supplier.modular.base.productions.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.supplier.modular.base.productions.entity.SupplierProductions;
import vip.xiaonuo.supplier.modular.base.productions.param.SupplierProductionsAddParam;
import vip.xiaonuo.supplier.modular.base.productions.param.SupplierProductionsEditParam;
import vip.xiaonuo.supplier.modular.base.productions.param.SupplierProductionsIdParam;
import vip.xiaonuo.supplier.modular.base.productions.param.SupplierProductionsPageParam;
import vip.xiaonuo.supplier.modular.base.productions.service.SupplierProductionsService;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 商品信息控制器
 *
 * @author Mr.wu
 * @date  2025/03/15 10:46
 */
@Tag(name = "商品信息控制器")
@RestController
@Validated
public class SupplierProductionsController {

    @Resource
    private SupplierProductionsService supplierProductionsService;

    /**
     * 获取商品信息分页
     *
     * @author Mr.wu
     * @date  2025/03/15 10:46
     */
    @Operation(summary = "获取商品信息分页")
    @SaCheckPermission("/supplier/base/productions/page")
    @GetMapping("/supplier/base/productions/page")
    public CommonResult<Page<SupplierProductions>> page(SupplierProductionsPageParam supplierProductionsPageParam) {
        return CommonResult.data(supplierProductionsService.page(supplierProductionsPageParam));
    }

    /**
     * 添加商品信息
     *
     * @author Mr.wu
     * @date  2025/03/15 10:46
     */
    @Operation(summary = "添加商品信息")
    @CommonLog("添加商品信息")
    @SaCheckPermission("/supplier/base/productions/add")
    @PostMapping("/supplier/base/productions/add")
    public CommonResult<String> add(@RequestBody @Valid SupplierProductionsAddParam supplierProductionsAddParam) {
        supplierProductionsService.add(supplierProductionsAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑商品信息
     *
     * @author Mr.wu
     * @date  2025/03/15 10:46
     */
    @Operation(summary = "编辑商品信息")
    @CommonLog("编辑商品信息")
    @SaCheckPermission("/supplier/base/productions/edit")
    @PostMapping("/supplier/base/productions/edit")
    public CommonResult<String> edit(@RequestBody @Valid SupplierProductionsEditParam supplierProductionsEditParam) {
        supplierProductionsService.edit(supplierProductionsEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除商品信息
     *
     * @author Mr.wu
     * @date  2025/03/15 10:46
     */
    @Operation(summary = "删除商品信息")
    @CommonLog("删除商品信息")
    @SaCheckPermission("/supplier/base/productions/delete")
    @PostMapping("/supplier/base/productions/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   List<SupplierProductionsIdParam> supplierProductionsIdParamList) {
        supplierProductionsService.delete(supplierProductionsIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取商品信息详情
     *
     * @author Mr.wu
     * @date  2025/03/15 10:46
     */
    @Operation(summary = "获取商品信息详情")
    @SaCheckPermission("/supplier/base/productions/detail")
    @GetMapping("/supplier/base/productions/detail")
    public CommonResult<SupplierProductions> detail(@Valid SupplierProductionsIdParam supplierProductionsIdParam) {
        return CommonResult.data(supplierProductionsService.detail(supplierProductionsIdParam));
    }
}
